#include <cstdio>

using namespace std;

char mem[257];
char A, B;
int pc;

int Hex2Dec(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    else
        return c - 'A' + 10;
}

int DHex2Dec(char a, char b)
{
    return Hex2Dec(a) * 16 + Hex2Dec(b);
}

char Dec2Hex(int i)
{
    if (i >= 10)
        return 'A' + i - 10;
    else
        return i + '0';
}

int main(void)
{
    while (scanf("%s", mem) && mem[0] != '8')
    {
        pc = 0;
        char command;
        char buf;
        int buf1, buf2;
        A = B = '0';
        while ((command = mem[pc]) != '8')
        {
            switch (command)
            {
            case '0': // LD
                A = mem[DHex2Dec(mem[pc + 1], mem[pc + 2])];
                pc += 3;
                break;
            case '1': // ST
                mem[DHex2Dec(mem[pc + 1], mem[pc + 2])] = A;
                pc += 3;
                break;
            case '2': // SWP
                buf = A;
                A = B;
                B = buf;
                ++pc;
                break;
            case '3': // ADD
                buf1 = Hex2Dec(A);
                buf2 = Hex2Dec(B);
                B = Dec2Hex((buf1 + buf2) / 16);
                A = Dec2Hex((buf1 + buf2) % 16);
                ++pc;
                break;
            case '4': // INC
                if (A == 'F')
                    A = '0';
                else if (A == '9')
                    A = 'A';
                else
                    ++A;
                ++pc;
                break;
            case '5': // DEC
                if (A == '0')
                    A = 'F';
                else if (A == 'A')
                    A = '9';
                else
                    --A;
                ++pc;
                break;
            case '6': // BZ
                if (A == '0')
                    pc = DHex2Dec(mem[pc + 1], mem[pc + 2]);
                else
                    pc += 3;
                break;
            case '7': // BR
                pc = DHex2Dec(mem[pc + 1], mem[pc + 2]);
                break;
            }
        }
        printf("%s\n", mem);
    }
    return 0;
}